<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <title>我的订单</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
    <meta name="apple-mobile-web-app-capable" content="yes" />
    <meta name="apple-mobile-web-app-status-bar-style" content="black" />
    <meta name="format-detection" content="telephone=no" />
    <link href="{$Think.config.RESOURCEURL}wx_assets/css/common.css{$Think.config.RESOURCE_VER}" rel="stylesheet" type="text/css">
    <link href="{$Think.config.RESOURCEURL}wx_assets/quan/orderList.css{$Think.config.RESOURCE_VER}" rel="stylesheet" type="text/css">
    <script type="text/javascript" src="{$Think.config.RESOURCEURL}wx_assets/js/zepto.1.1.3.min.js{$Think.config.RESOURCE_VER}"></script>
    <script src="{$Think.config.RESOURCEURL}wx_assets/js/util.js{$Think.config.RESOURCE_VER}" type="text/javascript"></script>
    <script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
    <script src="{$Think.config.RESOURCEURL}wx_assets/js/wx_share.js{$Think.config.RESOURCE_VER}" type="text/javascript"></script>
</head>
<body>
<div class="main" id="orderListBox">
</div>
<script type="text/javascript">
    template.helper("getTotal",function(price,logisticsCost){
        return (parseFloat(price)+(parseFloat(logisticsCost || 0))).toFixed(2);
    });
</script>
<script type="text/html" id="OrderListTpl">
    <% if(orderList) {
    for(var i=0,len=orderList.length;i<len;i++) {
    var item=orderList[i];
    %>
    <div class="order-box">
        <div class="order-inner order-award">
            <dl class="mi-box">
                <dd>
                    <img src="<%=item.headImgUrl%>"/>
                </dd>
                <dt><%=item.nickName%></dt>
            </dl>
            <div class="order-info" onclick="orderList.orderDetail(<%=item.id%>)">
                <span class="orderNumber">订单编号：<%=item.serialNumber || item.id%></span>
                <span class="status"><a>
                    <%if(item.status=='ok'){%>
                    交易成功
                    <%}%>
                    <%if(item.status=='notsubmit'){%>
                    未提交
                    <%}%>
                    <%if(item.status=='closed'){%>
                    交易关闭
                    <%}%>
                    <%if(item.status=='paying'){%>
                    等待付款
                    <%}%>
                    <%if(item.status=='delivering'){%>
                    等待发货
                    <%}%>
                    <%if(item.status=='delivered'){%>
                    已发货
                    <%}%>
                    <%if(item.status=='refund'){%>
                    已退款
                    <%}%>
                    <%if(item.status=='refunding'){%>
                    退款中
                    <%}%>
                    <%if(item.status=='payingconfirm'){%>
                    付款确认中
                    <%}%>
                </a></span>
            </div>
            <% if(item.productList) {
            for(var j=0;j<item.productList.length;j++) {
            var p=item.productList[j];
            %>
            <dl class="pro-list" onclick="orderList.toDetail('<%=p.fromCustomerId%>','<%=p.pid%>','<%=item.qId%>','<%=p.sId%>')">
                <dt>
                    <img src="<%=p.picUrl%>" onload="$.util.imgCenter(this)" />
                </dt>
                <dd>
                    <div class="name">
                        <a><%=p.name%></a>
                    </div>
                    <div class="price">
                        售价：<span>￥
                            <%if(p.disTotal) {%>
                                <%=p.disTotal%>
                            <%}else{%>
                                <%=p.fixedTotal%>
                            <%}%>
                            </span><br/>
                        佣金：<span>￥
                            <%if(p.lordAward&&p.lordAward!=0){%>
                                <%=p.lordAward%>
                            <%}else{%>
                                <%=p.lordTotalAward%>
                            <%}%>
                            </span>
                    </div>
                </dd>
            </dl>
            <%}%>
            <%}%>
        </div>
    </div>
    <%}%>
    <%} else {%>
    <div class="norecord">暂无相关订单</div>
    <%}%>
</script>
<script type="text/javascript">
    var baseUrl = '{$Think.config.SERVER_HOST}';
    var orderList={
        pageSize:10,
        page:0,
        init:function(){
            var me=this;
            this._initEvent();
            $.util.pageLoading.show();
            me._loadList(me.page,function(){
                $.util.pageLoading.hide();
            });
        },
        orderDetail:function(oid){
            var p={
                oid:oid,
                uType:2
            };
            p=encodeURIComponent(JSON.stringify(p));
            var detailUrl=baseUrl+'call.html?customerId={$customerId}&module=quan&method=getOrderDetail&params='+p;
            location.href=detailUrl;
        },
        toDetail:function(formCustomerId,pId,qId,sId){
            var p={
                qId:qId,
                sId:sId,
                id:pId
            };
            p=encodeURIComponent(JSON.stringify(p));
            var detailUrl=baseUrl+'call.html?customerId='+formCustomerId+'&module=product&method=getProduct&params='+p;
            location.href=detailUrl;
        },
        _initEvent:function(){
            var me=this;
            $(document).on("touchend",function(){
                var me=orderList;
                var topDis = document.body.scrollTop || document.documentElement.scrollTop,
                        viewHeight=$.util.page.getViewHeight(),
                        lastChildren=$("#orderListBox .order-box:last"),
                        coords=lastChildren[0].getBoundingClientRect(),
                        offset=0;
                if(coords.top-offset < viewHeight){
                    var page=me.page;
                    var pageCount=me.pageCount;
                    if(parseInt(page,10) < parseInt(pageCount,10) -1 ) {
                        $.util.dataLoading.show();
                        me._loadList(++page,function(){
                            $.util.dataLoading.hide();
                        });
                    }else {
                        $.util.dataEnd.show();
                    }
                }
            });
        },
        _renderList:function(data,page,callback){
            var me=this;
            if(data){
                var html=template("OrderListTpl", data),
                        container=$("#orderListBox");
                container.append(html);
                me.page=page;
                me.pageCount=data.pageCount;
                callback && callback();
            }
        },
        _loadList:function(page,callback){
            var me=this;
            $.req.get("call.json?module=quan&customerId={$customerId}&method=getOrderList",{
                userName:"{$userName}",
                params:{
                    "qId":"{$qId}",
                    "type":"2",
                    "start":page,
                    "limit":me.pageSize
                }
            },function(data){
                if(data){
                    me._renderList(data,page,callback);
                }
            });
        }
    }
    orderList.init();
    wx_share.init({
                "pkg":{
                    "appId": '{$pkg.appId}',
                    "timestamp": {$pkg.timestamp},
                "nonceStr": '{$pkg.nonceStr}',
                "signature": '{$pkg.signature}'
            },
            hide:1
    });
</script>
</body>
</html>